import request from "@/utils/request.js";

const indexApi = {
    SmsRefresh: '/page/boc/refresh_token/',
    Login: '/page/boc/login/', // 登录
    LoginSms: '/page/boc/sms/', //获取登录验证码
    SkuInfo: '/page/boc/sku/info/', // 商品详情
    SkuStock: '/page/boc/sku/stock/', // 查询sku库存
    BocObtain: '/page/boc/obtain/', //领取权益代金券
    OrderInfo: '/page/boc/order/info/', // 订单详情
    BocOrderList: '/page/boc/order/list/',//订单列表
    OauthCheck: '/page/boc/common/oauthCheck/',//授权验证
    PayGetPayParams: '/page/boc/pay/getPayParams/',// 获取微信JSAPI支付参数
    PayWechatPayNotify: '/page/boc/pay/wechatPayNotify',//微信支付回调
    BocCancelOrder: '/page/boc/cancelOrder/', // 取消订单
    PaySuccess: '/page/boc/pay/success/', // 支付成功
    CheckObtain:'/page/boc/check/obtain/', // 检查是否已经领取其它权益

}

let actId = 'b1LWD73vV'

// 登录
function login(param) {
    return request({
        url: indexApi.Login + actId,
        method: "POST",
        xhrFields: {
            withCredentials: true
        },
        params: param
    })
}

// 获取登录验证码
function loginSms(param) {
    return request({
        url: indexApi.LoginSms + actId,
        method: "POST",
        xhrFields: {
            withCredentials: true
        },
        // params: param,
        data: param
    })
}

// 商品详情
function skuInfo(skuId) {
    return request({
        url: indexApi.SkuInfo + actId + '/' + skuId,
        method: "POST",
        xhrFields: {
            withCredentials: true
        },
    })
}

//领取权益代金券
function bocObtain(skuId) {
    return request({
        url: indexApi.BocObtain + actId + '/' + skuId,
        xhrFields: {
            withCredentials: true
        },
        method: "POST",
    })
}

// 订单详情
function orderInfo(orderNo) {
    return request({
        url: indexApi.OrderInfo + actId + '/' + orderNo,
        method: "POST",
        xhrFields: {
            withCredentials: true
        },
    })
}

// 订单列表
function bocOrderList(params) {
    return request({
        url: indexApi.BocOrderList + actId,
        method: "POST",
        xhrFields: {
            withCredentials: true
        },
        params: params
    })
}

// 刷新token命令
function smsRefresh(token_type, refresh_token) {
    return request({
        url: indexApi.SmsRefresh + actId,
        method: 'POST',
        xhrFields: {withCredentials: true},
        headers: {Authorization: token_type + " " + refresh_token},
    })
}

//授权验证
function oauthCheck(scene) {
    return request({
        url: indexApi.OauthCheck + scene,
        method: "GET",
        // xhrFields: {withCredentials: true},
        header: {'X-Requested-With': XMLHttpRequest},
        // params: param
    })
}

// 获取微信JSAPI支付参数
function payGetPayParams(param) {
    return request({
        url: indexApi.PayGetPayParams + actId,
        method: 'POST',
        xhrFields: {withCredentials: true},
        data: param
    })
}

function bocCancelOrder(param) {
    return request({
        url: indexApi.BocCancelOrder + actId,
        method: 'POST',
        xhrFields: {withCredentials: true},
        data: param
    })
}

function skuStock(param) {
    return request({
        url: indexApi.SkuStock + actId,
        method: 'GET',
        xhrFields: {withCredentials: true},
        param: param
    })
}

function paySuccess(param) {
    return request({
        url: indexApi.PaySuccess + actId,
        method: 'POST',
        xhrFields: {withCredentials: true},
        data: param
    })
}
function checkObtain(skuId){
    return request({
        url: indexApi.CheckObtain + actId + '/' + skuId,
        method: 'POST',
        xhrFields: {withCredentials: true},
    })
}
//
// function prdList(params) {
//     return request({
//         url: indexApi.PrdList,
//         method: 'GET',
//         xhrFields: {
//             withCredentials: true
//         },
//         params: params
//     })
// }

export {
    smsRefresh,
    oauthCheck,
    loginSms,
    login,
    skuInfo,
    bocObtain,
    orderInfo,
    bocOrderList,
    skuStock,
    payGetPayParams,
    bocCancelOrder,
    paySuccess,
    checkObtain
}
